﻿using System;
using System.Linq;
using System.Collections.Generic; 
using NTTDATA.BEENChina.ResultCertification.Config; 

namespace NTTDATA.BEENChina.ResultCertification.Checker.Select
{
   
    [Serializable]
    [VerfityAttribute(Id = "VerfityS0202", Name = "文字栏的内容包含选项的结果抽出", CategoryType = EnumCategoryType.选择, Model = true)]
    public class VerfityS0202 : VerfityOneResult
    {

      

        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = false;

            if (entryCommon == "30"  )
            {
                return false;
            }

            if (result == null)
            {
                return false;
            }


            bresult = CheckSpecificCharacter( result,GetSpeicficResult, CheckResult ); 

           

            if (bresult)
            {
                System.Console.WriteLine("VerfityS0202");
            }

            return bresult;
        }


        private bool CheckResult(string colResult)
        {
            bool bresult = false;  

            if (String.IsNullOrEmpty(colResult))
            {
                return false;
            }
 
            var gridItems = ChildImageObject.CategorySetting.GridItems;

            if (gridItems != null)
            {
                bresult = gridItems.Any(t => colResult.Contains(t.Value));
            }

            return bresult;

/*
            if (ChildImageObject.CategorySetting.DataFormat.Contains("tx"))
            {
               

                
                var selectResult = splitResult.GetSelect();

                if ( !String.IsNullOrEmpty(selectResult))
                {
                    var selectResults = selectResult.Split('.');

                    if (selectResult.Any() )
                    {
                        var textResult = splitResult.GetText();


                        if (!String.IsNullOrEmpty(textResult))
                        {
                            bresult =  selectResults.Any( t=>
                                                              {
                                                                  bool bContains = false;
                                                                  string itemValue = ConvertSel(t);
                                                                  if (!string.IsNullOrEmpty(itemValue))
                                                                  {
                                                                      bContains = textResult.Contains(itemValue);
                                                                  }
                                                                  return bContains;
                                                              });
                            
                        }

                    }
                }
            }
*/
           

        }

        private string GetSpeicficResult(string colResult)
        {
            var splitResult = new Split.SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, colResult);
            return splitResult.GetText();

        }


        //private bool CheckspecificResult(string result)
        //{
        //    bool bresult = false;  

        //    if (!String.IsNullOrEmpty(result))
        //    {
        //        bresult = result.Equals("?");

        //    }
        //    return bresult;
        //}


        private string ConvertSel(string selResult)
        {
            var gridItems = ChildImageObject.CategorySetting.GridItems;


            string itemReuslt = string.Empty;

            if ( gridItems != null )
            {
                if (gridItems.ContainsKey(selResult))
                {
                    itemReuslt = gridItems[selResult];
                }
            }

            return itemReuslt;
        }


    }
}
